package portal.monitor.dao.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import portal.monitor.dao.MonitorPattern;
import portal.monitor.dao.mapper.MonitorPatternMapper;

import java.util.List;

@Service
public class MonitorPatternService {
    @Autowired
    MonitorPatternMapper monitorPatternMapper;

    public Integer insert(MonitorPattern monitorPattern){
        return monitorPatternMapper.insert(monitorPattern);
    }

    public Integer deleteByPrimaryKey(int patternId){
        return monitorPatternMapper.deleteByPrimaryKey(patternId);
    }

    public Integer updateByPrimaryKey(MonitorPattern monitorPattern){
        return monitorPatternMapper.updateByPrimaryKey(monitorPattern);
    }

    public MonitorPattern selectByPrimaryKey(int patternId){
        return monitorPatternMapper.selectByPrimaryKey(patternId);
    }

    public List<MonitorPattern> selectByPage(int currentPage, int onePageCount){
        if(onePageCount<1||currentPage<1) return  null;
        int currentPosition = (currentPage-1)*onePageCount;
        return monitorPatternMapper.selectByPage(currentPosition, onePageCount);
    }

    public Integer pageNum(Integer onePageCount){
        if(onePageCount<1) return -1;
        int patternNum = monitorPatternMapper.patternNum();
        return (patternNum%onePageCount==0)?(patternNum/onePageCount):(patternNum/onePageCount+1);
    }
    
    public List<MonitorPattern> selectAll(){
        return monitorPatternMapper.selectAll();
    }
}
